#include "MainWindow.h"
#include "OffScene.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
	ui.setupUi(this);

	scene = 0;
	glWidget = new GlWidget();
	setCentralWidget(glWidget);

	statusBar()->showMessage(tr("Welcome"));

	connect(ui.actionOpen_File,	SIGNAL(triggered()), this, SLOT(open()));
	connect(ui.actionClose_File, SIGNAL(triggered()), this, SLOT(close()));
	connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(exit()));
	connect(ui.actionXz_Plane, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionXy_Plane, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionYz_Plane, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionWireframe_Model, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionColored_Model, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionDot_Model, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionChose_Background_Color, SIGNAL(triggered()), this,
			SLOT(backgroundColor()));
	connect(ui.actionChoose_Object_Color, SIGNAL(triggered()), this,
			SLOT(objectColor()));
	connect(ui.actionShow_Coordinate_System, SIGNAL(toggled(bool)), this,
			SLOT(notYet()));
	connect(ui.actionReset_View, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionGerman, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionEnglish, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionHelp_Content, SIGNAL(triggered()), this, SLOT(notYet()));
	connect(ui.actionAbout_OffView, SIGNAL(triggered()), this, SLOT(about()));
	connect(ui.actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
}

MainWindow::~MainWindow()
{

}

void MainWindow::notYet()
{
	QMessageBox::information(this, tr("Not yet implemented..."),
			tr("That's something we have to work on."));
}

void MainWindow::open()
{
	QString file = QFileDialog::getOpenFileName(
	         this, tr("Open File"),
	         QDir::homePath(), tr("Off Files (*.off)"));

	if(!file.isNull()) {

		try {
			glWidget->setScene(0);
			if (scene)
				delete scene;
			scene = new OffScene(file);
			glWidget->setScene(scene);
		}

		catch (...) {
			// As soon as the parser will throw exceptions, I will
			// catch them here...
		}
	}

}

void MainWindow::close()
{
	glWidget->setScene(0);
	if (scene)
		delete scene;
	scene = 0;
}

void MainWindow::exit()
{
	QApplication::exit();
}

void MainWindow::backgroundColor()
{
	notYet();
}

void MainWindow::objectColor()
{
	QColor color;
	color = QColorDialog::getColor(QColor(255, 255, 255),
			this, tr("Choose Object Color"));
}

void MainWindow::about()
{
	QMessageBox::information(this, tr("About OffView"), tr("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."));
}

void MainWindow::aboutQt()
{
	QApplication::aboutQt();
}
